//
//  ViewController.swift
//  HWBanner
//
//  Created by fuyoufang on 2021/10/14.
//

import UIKit

class ViewController: UIViewController {

    // MARK: Constant
    struct Constant {
        static let cellIdentifier = "cell"
    }
    
    lazy var collectionView: UICollectionView = {
        let layout = HWCollectionViewFlowLayout()
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.register(BannerCell.self, forCellWithReuseIdentifier: Constant.cellIdentifier)
        collectionView.backgroundColor = .clear
        collectionView.dataSource = self
        return collectionView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(collectionView)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        collectionView.frame = CGRect(x: 0, y: 100, width: view.bounds.size.width, height: 200)
    }


}

extension ViewController: UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Constant.cellIdentifier, for: indexPath) as! BannerCell
        
        cell.titleLabel.text = "title \(indexPath.row)"
        
        return cell
    }
}
